package com.zzyl.controller.nursing;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目
 * Controller类
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    private final NursingProjectService nursingProjectService;

    public NursingProjectController(NursingProjectService nursingProjectService) {
        this.nursingProjectService = nursingProjectService;
    }


    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称") String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingProjectPageInfo);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto dto) {
        int row = nursingProjectService.insertProject(dto);
        return this.toAjax(row);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目信息")
    public ResponseResult<NursingProjectVo> getById(@ApiParam(value = "护理项目id") @PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.selectById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("修改护理项目信息")
    public ResponseResult update(@RequestBody NursingProjectDto dto) {
        int row = nursingProjectService.updateProject(dto);
        return this.toAjax(row);
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理项目状态")
    public ResponseResult updateStatus(@ApiParam(value = "护理项目id") @PathVariable Long id,
                                       @ApiParam(value = "状态：0-禁用，1-启用") @PathVariable Integer status) {
        int row = nursingProjectService.updateStatus(id, status);
        return this.toAjax(row);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult delete(@ApiParam(value = "护理项目id") @PathVariable Long id) {
        int row = nursingProjectService.deleteById(id);
        return this.toAjax(row);
    }

    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<PageResponse<List<NursingProjectVo>>> selectAll() {
        List<NursingProjectVo> nursingProjectVoList = nursingProjectService.selectAll();
        return ResponseResult.success(nursingProjectVoList);
    }

}